package approve.adapter;

import java.text.DecimalFormat;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TableRow;
import android.widget.TextView;
import approve.action.App_ViewForm17;
import approve.action.R;
import approve.model.Advance;

public class AdvanceAdapter extends BaseAdapter{
	private Context context;
	private List<Advance> lstAdvance;
	private Bundle language;
	TableRow flag = null;
	ViewHolder  holder;
	public AdvanceAdapter(App_ViewForm17 context, List<Advance> lstAdvance,
			Bundle language) {
		super();
		this.context = context;
		this.lstAdvance = lstAdvance;
		this.language = language;
	}

	@Override
	public int getCount() {
		return lstAdvance.size();
	}

	@Override
	public Object getItem(int arg0) {
		return lstAdvance.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertview, ViewGroup arg2) {
		Advance advance = lstAdvance.get(position);
		DecimalFormat df = new DecimalFormat("#.#");
		
		if(convertview==null){
			holder = new ViewHolder();
			
			LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertview=inflater.inflate(R.layout.adapter_purchaseorder_viewform13, arg2,false);
			
			holder.lbItem = (TextView)convertview.findViewById(R.id.lbNameProduct13);
			holder.lbItem.setText("+"+" "+language.getString("items")+": ");
			holder.lbItem.setTextColor(Color.YELLOW);
			
			holder.lbTotal = (TextView)convertview.findViewById(R.id.lbTotalProduct13);
			holder.valTotal = (TextView)convertview.findViewById(R.id.valuesTotalPro13);
			
			holder.valueItem = (TextView)convertview.findViewById(R.id.valuesNamePro13);
			
			convertview.setTag(holder);
			
			holder.lbTotal.setText("    "+language.getString("total")+": ");
			holder.lbTotal.setTextColor(Color.YELLOW);
			
			holder.valTotal.setText(df.format(advance.getMoney())+"");
			
		}else{
			holder = (ViewHolder)convertview.getTag();
		}
		
		holder.valueItem.setText(advance.getItems());
		
		return convertview;
	}

	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}

	public List<Advance> getLstAdvance() {
		return lstAdvance;
	}

	public void setLstAdvance(List<Advance> lstAdvance) {
		this.lstAdvance = lstAdvance;
	}

	public Bundle getLanguage() {
		return language;
	}

	public void setLanguage(Bundle language) {
		this.language = language;
	}

	public static class ViewHolder{
		TextView lbItem,valueItem,lbTotal,valTotal;
	}
}
